using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region UserRole

	/// <summary>
	/// UserRole object for NHibernate mapped table 'UserRole'.
	/// </summary>
	[Serializable]
	public class UserRole : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected Nullables.NullableDateTime _delegateStartDate;
		protected Nullables.NullableDateTime _delegateEndDate;
		protected Nullables.NullableDateTime _modifyDateTime;
		protected string _modifyType;
		protected bool _isEnabled;
		protected Employee _delegateUser;
		protected Employee _employee;
		protected Role _role;
		protected Department _cATBranch;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public UserRole() { }

		public UserRole( Nullables.NullableDateTime delegateStartDate, Nullables.NullableDateTime delegateEndDate, Nullables.NullableDateTime modifyDateTime, string modifyType, bool isEnabled, Employee delegateUser, Employee employee, Role role, Department cATBranch )
		{
			this._delegateStartDate = delegateStartDate;
			this._delegateEndDate = delegateEndDate;
			this._modifyDateTime = modifyDateTime;
			this._modifyType = modifyType;
			this._isEnabled = isEnabled;
			this._delegateUser = delegateUser;
			this._employee = employee;
			this._role = role;
			this._cATBranch = cATBranch;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public Nullables.NullableDateTime DelegateStartDate
		{
			get { return _delegateStartDate; }
			set { _delegateStartDate = value; }
		}

		public Nullables.NullableDateTime DelegateEndDate
		{
			get { return _delegateEndDate; }
			set { _delegateEndDate = value; }
		}

		public Nullables.NullableDateTime ModifyDateTime
		{
			get { return _modifyDateTime; }
			set { _modifyDateTime = value; }
		}

		public string ModifyType
		{
			get { return _modifyType; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for ModifyType", value, value.ToString());
				_modifyType = value;
			}
		}

		public bool IsEnabled
		{
			get { return _isEnabled; }
			set { _isEnabled = value; }
		}

		public Employee DelegateUser
		{
			get { return _delegateUser; }
			set { _delegateUser = value; }
		}

		public Employee Employee
		{
			get { return _employee; }
			set { _employee = value; }
		}

		public Role Role
		{
			get { return _role; }
			set { _role = value; }
		}

		public Department CATBranch
		{
			get { return _cATBranch; }
			set { _cATBranch = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is UserRole))
				throw new InvalidCastException("This object is not of type UserRole");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((UserRole)obj).Id);
					break;
				case "DelegateStartDate":
						relativeValue = ( this.DelegateStartDate != null ) ? this.DelegateStartDate.CompareTo(((UserRole)obj).DelegateStartDate) : -1;
					break;
				case "DelegateEndDate":
						relativeValue = ( this.DelegateEndDate != null ) ? this.DelegateEndDate.CompareTo(((UserRole)obj).DelegateEndDate) : -1;
					break;
				case "ModifyDateTime":
						relativeValue = ( this.ModifyDateTime != null ) ? this.ModifyDateTime.CompareTo(((UserRole)obj).ModifyDateTime) : -1;
					break;
				case "ModifyType":
						relativeValue = ( this.ModifyType != null ) ? this.ModifyType.CompareTo(((UserRole)obj).ModifyType) : -1;
					break;
				case "IsEnabled":
						relativeValue = ( this.IsEnabled != Convert.ToBoolean( null) ) ? this.IsEnabled.CompareTo(((UserRole)obj).IsEnabled) : -1;				
					break;
                default:
                    goto case "Id";
			}
            if (UserRole.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
